import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateCategoryDto } from './dto/creater.dto';
import { Category } from './entities/category.entity';
import { responseData } from '../common/response.handle';

@Injectable()
export class CategoryService {
	constructor(
		@InjectRepository(Category)
		private categoryRepository: Repository<Category>,
	) {}

	async create(createProfileDto: CreateCategoryDto, userId: string) {
		await this.categoryRepository.save(
			this.categoryRepository.create({
				...createProfileDto,
				creator: userId,
			}),
		);
		return responseData(null, '创建分类成功');
	}

	async findAll() {
		const res = await this.categoryRepository.find();

		return responseData(res, '获取分类成功');
	}
}
